package UserInfo;

import org.json.JSONObject;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.ProtocolException;
import java.net.URL;

public class WechatUser {
   public static String WechatUser(String userId,String accessToken){
       String url = "https://qyapi.weixin.qq.com/cgi-bin/user/get?access_token="+accessToken+"&userid="+userId;
       try {
           URL url1 = new URL(url);
           HttpURLConnection httpURLConnection= (HttpURLConnection) url1.openConnection();
           httpURLConnection.setRequestMethod("GET");

           BufferedReader bufferedReader=new BufferedReader(new InputStreamReader(httpURLConnection.getInputStream()));
           String line=null;
           StringBuilder builder=new StringBuilder();
           while ((line=bufferedReader.readLine())!=null){
               builder.append(line);
           }
           JSONObject jsonObject=new JSONObject(builder);
           bufferedReader.close();
           return jsonObject.toString();
       } catch (MalformedURLException e) {
           throw new RuntimeException(e);
       } catch (ProtocolException e) {
           throw new RuntimeException(e);
       } catch (IOException e) {
           throw new RuntimeException(e);
       }
   }
}
